package com.hz.ruoyilgorder.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hz.rouyigonggong.domain.LgSellerOrder;
import com.hz.rouyigonggong.domain.dto.LgSellerOrderBySellerIdDTO;
import com.hz.rouyigonggong.domain.dto.LgSellerOrderDTO;
import com.hz.rouyigonggong.utils.ResultJSON;
import com.hz.ruoyilgorder.mapper.LgSellerOrderDTOMapper;
import com.hz.ruoyilgorder.mapper.LgSellerOrderMapper;
import com.hz.ruoyilgorder.service.LgSellerOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @version 1.0
 * @Author yzw
 * @Date 2025/3/5 9:44
 * @注释
 */
@Service
public class LgSellerOrderServiceImpl extends ServiceImpl<LgSellerOrderMapper, LgSellerOrder> implements LgSellerOrderService {

    @Autowired
    private LgSellerOrderMapper lgSellerOrderMapper;
    @Autowired
    private LgSellerOrderDTOMapper lgSellerOrderDTO;


    @Override
    public List<LgSellerOrderDTO> getLgSellerOrderList(LgSellerOrderDTO entity ) {


        return lgSellerOrderDTO.querylist( entity);
    }

    @Override
    public LgSellerOrderDTO getInfo(Integer orderNumber) {

        return lgSellerOrderDTO.byId(orderNumber);
    }

    @Override
    public List<Integer> getDailyOrders(LocalDateTime startDate, LocalDateTime endDate) {
        List<Integer> dailyOrders = new ArrayList<>();

        // 遍历日期范围内的每一天
        for (LocalDateTime date = startDate; !date.isAfter(endDate); date = date.plusDays(1)) {
            LocalDateTime startOfDay = date.withHour(0).withMinute(0).withSecond(0);
            LocalDateTime endOfDay = date.withHour(23).withMinute(59).withSecond(59);

            // 查询当天的订单数量
            int orderCount = lgSellerOrderMapper.countOrdersBetween(startOfDay, endOfDay);
            dailyOrders.add(orderCount);
        }
        return dailyOrders;
    }

    @Override
    public List<LgSellerOrderBySellerIdDTO> getLgSellerOrderBySellerId(Integer sellerId) {
        return lgSellerOrderMapper.getLgSellerOrderBySellerId(sellerId);
    }

    @Override
    public LgSellerOrderBySellerIdDTO getLgSellerOrderById(Integer orderId) {
        return lgSellerOrderMapper.getLgSellerOrderById(orderId);
    }
}
